<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				设备下拨
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="left">下拨总计：{{checknum}}台</view>
			<view class="desc">下拨SN： 
				<text v-for="(item,index) in deviceList" :key="index">
					{{item.sn}},
				</text>
			</view>
			<view class="center">
				<view class="sousuo">
					<input type="text" placeholder="请输入商户名称" v-model="formData.search" />
					<image :src="baseUrl + '/wximage/sousuo.png'" @click="searchClick()" ></image>
				</view>
			</view>
		</view>
		<view class="mendian">
			
			<view class="heads clearfix">
				<view class="left fl">
					<image :src="baseUrl + '/wximage/hktubiao.png'"></image>
					<view class="name">商户</view>
				</view>
			</view>
			
			<view class="shuju" v-if="businessList.length != 0">
				<view class="li clearfix" @click="xuanzhong(item.id)" v-for="(item,index) in businessList">
					<image :src="baseUrl + '/wximage/saoma.png'" class="fl"></image>
					<view class="cen fl">
						<text class="title">{{item.nickname}}</text>
						<!-- <text class="address">商户地址：{{item.full_address}}</text> -->
						<text class="time">创建时间：{{item.created_at}}</text>
					</view>
				</view>
			</view>
			<view class="empty" v-else>
				<image :src="baseUrl + '/wximage/empty.png'"></image>
				<text>暂无商户数据</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				list: [1],
				deviceList: [],
				checknum:0,
				formData: {
					agent_id:uni.getStorageSync('agent_id'),
					page:1,
					pageSize:30,
					search:'',
					type:1
				},
				businessList: [],
				attr:1
			}
		},
		onLoad(options) {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			this.deviceList = JSON.parse(options.checkarr);
			this.checknum = options.checknum;
			this.attr = options.attr;
			//查询商户列表
			this.getBussinessList();
		},
		onReachBottom() {
			// console.log("onReachBottom11111");
			this.formData.page = this.formData.page+1;
			this.getBussinessList();
		},
		methods: {
			searchClick(){
				this.formData.page =1;
				this.businessList = [];
				this.getBussinessList();
				
			},
			getBussinessList(){
				this.request({
					url: '/wxdevice/bussinesslist',
					data: this.formData,
					method: "GET"
				}).then(res => {
					if (res.data.code == 200) {
						// console.log(res);
						if(res.data.data.list.length!=0){
							this.businessList = res.data.data.list;
							// this.bussinessList = this.bussinessList.concat(res.data.data);
						}
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				});
			},
			xuanzhong(id){
				
				this.request({
					url: '/wxdevice/llocatedsure',
					data: {devicenumber: JSON.stringify(this.deviceList),bussinessid:id,attr:this.attr,agent_id:uni.getStorageSync('agent_id')},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						// uni.showToast({
						// 	title: '分配成功！',
						// 	icon: 'none',
						// })
						uni.navigateTo({
							url: '/subpackageA/equipment/xiabomendian?devicenumber='+JSON.stringify(this.deviceList)+'&bussinessid='+id
						})
						// console.log(res);
						// if(res.data.data.list.length!=0){
							// this.businessList = res.data.data.list;
							// this.bussinessList = this.bussinessList.concat(res.data.data);
						// }
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						})
					}
				});
				
				
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.equipment {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;

			.left {
				font-size: 32rpx;
				color: #333333;
				font-weight: 700;
			}
			
			.desc{
				font-size: 24rpx;
				color: #666666;
				width: 100%;
				white-space: normal;
				margin-top: 20rpx;
			}
			
			.center{
				margin-top: 30rpx;
				
				.sousuo {
					width: 100%;
					box-sizing: border-box;
					position: relative;
						
					input {
						width: 100%;
						height: 60rpx;
						line-height: 60rpx;
						background: #ffffff;
						border-radius: 30rpx;
						padding-left: 30rpx;
						color: #999999;
						box-sizing: border-box;
					}
						
					image {
						width: 72rpx;
						height: 40rpx;
						position: absolute;
						right: 10rpx;
						top: 10rpx;
					}
					
					.iconfont {
						font-size: 40rpx;
						position: absolute;
						right: 24rpx;
						top: 10rpx;
						color: #5C88FA;
					}
				}
			}
		}
		
		.mendian{
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: -30rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
			
			.heads{
				width: 100%;
				padding: 24rpx 20rpx 0;
				box-sizing: border-box;
				
				.left{
					
					image{
						float: left;
						width: 40rpx;
						height: 40rpx;
						margin-top: -6rpx;
					}
					
					.name{
						font-size: 28rpx;
						color: #333333;
						float: left;
					}
				}
				
				.right{
					
					image{
						float: left;
						width: 40rpx;
						height: 40rpx;
						margin-top: -6rpx;
					}
					
					.name{
						font-size: 28rpx;
						color: #368BF8;
						float: left;
					}
				}
			}
			
			.shuju{
				width: 100%;
				padding: 30rpx 26rpx;
				box-sizing: border-box;
				
				.li{
					width: 100%;
					position: relative;
					padding-bottom: 40rpx;
					margin-bottom: 40rpx;
					border-bottom: 1rpx solid #F1F1F1;
					
					image{
						width: 120rpx;
						height: 120rpx;
					}
					
					.cen{
						width: 480rpx;
						margin-left: 20rpx;
						
						text{
							display: block;
						}
						
						.title{
							font-size: 28rpx;
							color: #333333;
							font-weight: 700;
							margin-bottom: 10rpx;
						}
						
						.address{
							font-size: 24rpx;
							color: #666666;
							margin-bottom: 6rpx;
						}
						
						.time{
							font-size: 24rpx;
							color: #999999;
						}
					}
					
					.bili{
						position: absolute;
						right: 0;
						bottom: 40rpx;
						width: 120rpx;
						height: 32rpx;
						line-height: 32rpx;
						text-align: center;
						background: #3B91F8;
						color: #FFFFFF;
						border-radius: 16rpx;
						font-size: 22rpx;
					}
				}
				
				.li:last-child{
					border: none;
					margin-bottom: 0;
					padding-bottom: 0;
				}
			}
		}
		
		.empty{
			width: 100%;
			margin: 20rpx auto 0;
			text-align: center;
			padding-bottom: 20rpx;
			
			image{
				width: 390rpx;
				height: 340rpx;
			}
			
			text{
				display: block;
				margin-top: 30rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>